import os

from tornado.web import Application

from app.ui.menu import MenuModule
from app.ui.nav import NavModule
from app.view.download import DownloadHandler, AsyncDownloadHandler
from app.view.index_v import IndexHandler
from app.view.cookie_v import CookieHandler
from app.view.order_v import OrderHandler
from app.view.search_v import SearchHandler


BASE_DIR = os.path.dirname((os.path.abspath(os.path.dirname(__file__))))#/microserver


settings ={
    'debug':True,
    'template_path':os.path.join(BASE_DIR,'templates'),
    'static_path':os.path.join(BASE_DIR,'static'),
    'static_url_prefix': '/s/',
    'ui_modules':{
        'Nav': NavModule,
        'Menu': MenuModule,
    }
}

def make_app(host='localhost'):

    return Application([
        ('/', IndexHandler),
        ('/search', SearchHandler),
        ('/cookie', CookieHandler),
        (r'/order/(?P<order_id>\d+)/(?P<action_code>\d+)', OrderHandler),
        ('/download', AsyncDownloadHandler),
    ],default_host=host,**settings)